﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Collections.Generic;

namespace Nok_Air
{
    public class AirportCodeToNameConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            foreach (NokObjects.AirportItem port in App.ViewModel.AvailableAirportItemsSrc)
            {
                if (port.AirportCode == value.ToString()) return port.AirPortName;
            }
            return "";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            foreach (NokObjects.AirportItem port in App.ViewModel.AvailableAirportItemsSrc)
            {
                if (port.AirPortName == value.ToString()) return port.AirportCode;
            }
            return "";
        }
    }

    public class DayConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //   DateTime time = System.Convert.ToDateTime(value);
            //    double Angle = time.Hour * 30;
            //    Angle += 12 * time.Minute / 60;
            DateTime dt = (DateTime)value;
            string date = "";
            if (App.lang == "eng")
            {
                date = String.Format("{0:dddd, MMMM d, yyyy}", dt);
            }
            else
            {

             //   var tmpDate = String.Format("{0:d/ddd/MM/yyyy}", value).Split('/');
                string numDate = dt.Day.ToString(); //tmpDate[0];
                string day = dt.DayOfWeek.ToString();//tmpDate[1];
                string mounth = dt.Month.ToString();//tmpDate[2];
                int year = dt.Year + 543;


                switch (day.Substring(0,3))
                {
                    case "Sun": day = "อาทิตย์"; break;
                    case "Mon": day = "จันทร์"; break;
                    case "Tue": day = "อังคาร"; break;
                    case "Wed": day = "พุธ"; break;
                    case "Thu": day = "พฤหัสบดี"; break;
                    case "Fri": day = "ศุกร์"; break;
                    case "Sat": day = "เสาร์"; break;
                }
                switch (mounth)
                {
                    case "1": mounth = "มกราคม"; break;
                    case "2": mounth = "กุมภาพันธ์"; break;
                    case "3": mounth = "มีนาคม"; break;
                    case "4": mounth = "เมษายน"; break;
                    case "5": mounth = "พฤษภาคม"; break;
                    case "6": mounth = "มิถุนายน"; break;
                    case "7": mounth = "กรกฎาคม"; break;
                    case "8": mounth = "สิงหาคม"; break;
                    case "9": mounth = "กันยายน"; break;
                    case "10": mounth = "ตุลาคม"; break;
                    case "11": mounth = "พฤศจิกายน"; break;
                    case "12": mounth = "ธันวาคม"; break;
                }

                date = day + " ที่ " + numDate + " " + mounth + " " + year;
            }
            //  MessageBox.Show(value.ToString());
            return date;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class DayConverter2 : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string date = (string)value;
            string dateNum = date.Substring(0, 2);
            string mounth = date.Substring(2, 3).ToLower();
            string year = date.Substring(5, 4);

            
            if (App.lang == "eng")
            {

                switch (mounth)
                {
                    case "jan": mounth = "January"; break;
                    case "feb": mounth = "February"; break;
                    case "mar": mounth = "March"; break;
                    case "apr": mounth = "April"; break;
                    case "may": mounth = "May"; break;
                    case "jun": mounth = "June"; break;
                    case "jul": mounth = "July"; break;
                    case "aug": mounth = "August"; break;
                    case "sep": mounth = "September"; break;
                    case "oct": mounth = "October"; break;
                    case "nov": mounth = "November"; break;
                    case "dec": mounth = "December"; break;
                }

                date = mounth + " " + dateNum + ", " + year;
            }
            else
            {

                year = (int.Parse(year) + 543).ToString();
                
                switch (mounth)
                {
                    case "jan": mounth = "มกราคม"; break;
                    case "feb": mounth = "กุมภาพันธ์"; break;
                    case "mar": mounth = "มีนาคม"; break;
                    case "apr": mounth = "เมษายน"; break;
                    case "may": mounth = "พฤษภาคม"; break;
                    case "jun": mounth = "มิถุนายน"; break;
                    case "jul": mounth = "กรกฎาคม"; break;
                    case "aug": mounth = "สิงหาคม"; break;
                    case "sep": mounth = "กันยายน"; break;
                    case "oct": mounth = "ตุลาคม"; break;
                    case "nov": mounth = "พฤศจิกายน"; break;
                    case "dec": mounth = "ธันวาคม"; break;
                }

                date = "วันที่ " + dateNum + " " + mounth + " พ.ศ." + year;
            }
            //  MessageBox.Show(value.ToString());
            return date;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }

      public class DayConverter3 : IValueConverter
    { 
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //2011-05-03
            string date = (string)value;
            string dateNum = date.Split('-')[2];
            string mounth = date.Split('-')[1];
            string year = date.Split('-')[0];

            
            if (App.lang == "eng")
            {

                switch (mounth)
                {
                    case "01": mounth = "January"; break;
                    case "02": mounth = "February"; break;
                    case "03": mounth = "March"; break;
                    case "04": mounth = "April"; break;
                    case "05": mounth = "May"; break;
                    case "06": mounth = "June"; break;
                    case "07": mounth = "July"; break;
                    case "08": mounth = "August"; break;
                    case "09": mounth = "September"; break;
                    case "10": mounth = "October"; break;
                    case "11": mounth = "November"; break;
                    case "12": mounth = "December"; break;
                }

                date = mounth + " " + dateNum + ", " + year;
            }
            else
            {

                year = (int.Parse(year) + 543).ToString();
                
                switch (mounth)
                {
                    case "01": mounth = "มกราคม"; break;
                    case "02": mounth = "กุมภาพันธ์"; break;
                    case "03": mounth = "มีนาคม"; break;
                    case "04": mounth = "เมษายน"; break;
                    case "05": mounth = "พฤษภาคม"; break;
                    case "06": mounth = "มิถุนายน"; break;
                    case "07": mounth = "กรกฎาคม"; break;
                    case "08": mounth = "สิงหาคม"; break;
                    case "09": mounth = "กันยายน"; break;
                    case "10": mounth = "ตุลาคม"; break;
                    case "11": mounth = "พฤศจิกายน"; break;
                    case "12": mounth = "ธันวาคม"; break;
                }

                date = dateNum + " " + mounth + " พ.ศ." + year;
            }
            //  MessageBox.Show(value.ToString());
            return date;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
      public class DayConverter4 : IValueConverter
      {
          #region IValueConverter Members

          public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              //2011/05/17
              string date = (string)value;
              string year = date.Substring(0, 4);
              string mounth = date.Substring(5, 2);
              string dateNum = date.Substring(8, 2);              


              if (App.lang == "eng")
              {

                  switch (mounth)
                  {
                      case "01": mounth = "January"; break;
                      case "02": mounth = "February"; break;
                      case "03": mounth = "March"; break;
                      case "04": mounth = "April"; break;
                      case "05": mounth = "May"; break;
                      case "06": mounth = "June"; break;
                      case "07": mounth = "July"; break;
                      case "08": mounth = "August"; break;
                      case "09": mounth = "September"; break;
                      case "10": mounth = "October"; break;
                      case "11": mounth = "November"; break;
                      case "12": mounth = "December"; break;
                  }

                  date = mounth + " " + dateNum + ", " + year;
              }
              else
              {

                  year = (int.Parse(year) + 543).ToString();

                  switch (mounth)
                  {
                      case "01": mounth = "มกราคม"; break;
                      case "02": mounth = "กุมภาพันธ์"; break;
                      case "03": mounth = "มีนาคม"; break;
                      case "04": mounth = "เมษายน"; break;
                      case "05": mounth = "พฤษภาคม"; break;
                      case "06": mounth = "มิถุนายน"; break;
                      case "07": mounth = "กรกฎาคม"; break;
                      case "08": mounth = "สิงหาคม"; break;
                      case "09": mounth = "กันยายน"; break;
                      case "10": mounth = "ตุลาคม"; break;
                      case "11": mounth = "พฤศจิกายน"; break;
                      case "12": mounth = "ธันวาคม"; break;
                  }

                  date = "วันที่ " + dateNum + " " + mounth + " พ.ศ." + year;
              }
              //  MessageBox.Show(value.ToString());
              return date;
          }

          public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              // Not required.
              return null;
          }

          #endregion
      }
    public class DepartuerOrReturnFlightSegment : IValueConverter
    { 
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int index = App.ViewModel.FlightSegmentItems.IndexOf(value as FlightSegmentItemViewModel);
            string type = "";

            switch (index)
            {
                case 0: type = App.ViewModel.Depart2; break;
                case 1: type = App.ViewModel.Return2; break;
            }

            return type;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class DepartuerOrReturnSellingClass : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int index = App.ViewModel.AvailabilityItems.IndexOf(value as AvailabilityItemViewModel);
            string type = "";

            switch (index)
            {
                case 0: type = App.ViewModel.Depart2; break;
                case 1: type = App.ViewModel.Return2; break;
            }

            return type;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class DepartuerOrReturn : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string flightInfo = "";

            switch ((string)value)
            {
                case "1": flightInfo = App.ViewModel.Depart2; break;
                case "2": flightInfo = App.ViewModel.Return2 ; break;
            }

            return flightInfo;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class SellingClsCodeConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string ClassInfo = "";

            List<string> nokplus = new List<string>() { "X", "C", "D", "J" };
            List<string> nokflexi = new List<string>() { "Y", "Q", "H" };

            if (nokplus.Contains((string)value))
            {
                ClassInfo = App.ViewModel.NokPlus;
            }
            else if (nokflexi.Contains((string)value))
            {
                ClassInfo = App.ViewModel.NokFlexi;
            }
            else
            {
                ClassInfo = App.ViewModel.NokEco;
            }

            return ClassInfo;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class PassengerTypeConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string PassengerType = (string)value;

            switch ((string)value)
            {
                case "ADULT": PassengerType = App.ViewModel.Adult; break;
                case "CHD"  : PassengerType = App.ViewModel.Children; break;
            }

            return PassengerType;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }

   
    public class GroupSellingClassEconomyConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            FSegSellingClass _class = (FSegSellingClass)value;
            if (_class.ClassCode == null && _class.ClassName == null && _class.FareValue == null)
            {
                _class = new FSegSellingClass() { ClassName = App.ViewModel.NokEco, FareValue = "SOLD OUT", IsEnable = "False" };
            }
            else
            {
                _class.IsEnable = "True";
            }
            return _class;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class GroupSellingClassFlexiConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            FSegSellingClass _class = (FSegSellingClass)value;
            if (_class.ClassCode == null && _class.ClassName == null && _class.FareValue == null)
            {
                _class = new FSegSellingClass() { ClassName = App.ViewModel.NokFlexi, FareValue = "SOLD OUT", IsEnable = "False" };
            }
            else
            {
                _class.IsEnable = "True";
            }
            return _class;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class GroupSellingClassNokPlusConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            FSegSellingClass _class = (FSegSellingClass)value;
            if (_class.ClassCode == null && _class.ClassName == null && _class.FareValue == null)
            {
                _class = new FSegSellingClass() { ClassName = App.ViewModel.NokPlus, FareValue = "SOLD OUT", IsEnable = "False" };
            }
            else
            {
                _class.IsEnable = "True";
            }
            return _class;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }

    public class NameSeparateConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string[] name = ((string)value).Split('/');

            return name[0] + Environment.NewLine + name[1];
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class SeatStatusConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            bool Status = true;
            /*
                V=Vacant Seat 
                B=Block Seat
                R=Reserve Seat via website (for passenger who reserved this seat only)
                P=Pre seat by station(for passenger who reserved this seat only)
                O=already checked-in

             */
            switch ((string)value)
            {
                case "V": Status = true; break;
                case "B": Status = false; break;
                default: Status = false; break;
            }

            return Status;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class CheckinStatusConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            String Status = "";
            /*
                V=Vacant Seat 
                B=Block Seat
                R=Reserve Seat via website (for passenger who reserved this seat only)
                P=Pre seat by station(for passenger who reserved this seat only)
                O=already checked-in

             */
            switch ((string)value)
            {
                case "N": Status = App.ViewModel.CheckinStatusN; break;
                case "Y": Status = App.ViewModel.CheckinStatusY; break;
                default: Status = App.ViewModel.CheckinStatusNS; break;
            }

            return Status;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class CheckinStatusColorConverter : IValueConverter
    {
        private Color N = new Color() { R = 151, G = 182, B = 255, A=255};
        private Color Y = new Color() { R = 168, G = 255, B = 159, A=255};
        private Color defcolor = new Color() { R = 255, G = 218, B = 159, A=255 };
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            SolidColorBrush _color = new SolidColorBrush(Colors.White);
            switch ((string)value)
            {
                case "N": _color = new SolidColorBrush(N); break;
                case "Y": _color = new SolidColorBrush(Y); break;
                default: _color = new SolidColorBrush(defcolor); break;
            }

            return _color;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }
    public class BarcodeConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string uri = "http://dev.nokair.com:8080/NokCheckinService/" + (string)value;

            return uri;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not required.
            return null;
        }

        #endregion
    }   
}
